﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Test.LotteryService;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
using System.ServiceModel.Channels;

namespace Test
{
	class Program
	{
		static void Main(string[] args)
		{
			LotteryServiceClient client = WcfProxy.GetProxy;
			string sq = client.Test();
			Console.WriteLine(sq);
		}
	}

	public class WcfProxy
	{
		public WcfProxy() { }
		public static LotteryServiceClient GetProxy
		{
			get
			{
				EndpointAddress address = new EndpointAddress(Constant.WcfSrvIp);
				BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.None);
				binding.ReceiveTimeout = new TimeSpan(0, 10, 0);
				binding.SendTimeout = new TimeSpan(0, 10, 0);
				binding.MaxReceivedMessageSize = 2147483647;
				binding.OpenTimeout = new TimeSpan(0, 10, 0);
				binding.CloseTimeout = new TimeSpan(0, 10, 0);
				LotteryServiceClient client = new LotteryServiceClient(binding, address);
				EndpointBehavior endpointBehavior = new EndpointBehavior();
				client.Endpoint.Behaviors.Add(endpointBehavior);
				return client;
			}
		}
	}

	public class ProfitTypeInfo
	{
		public ProfitTypeInfo(short typeid, string typename)
		{
			this.TypeId = typeid;
			this.TypeName = typename;
		}

		public short TypeId { get; set; }

		public string TypeName { get; set; }
	}
	public class Constant
	{
		public static double BaseScale = 1850;
		public static double BaseMinScale = 1600;
		public static double MaxScale = 1920;
		public static double MinScale = 1600;
		public static int Multiple = 1;

		public static double MaxBonusPct = 5;

		public static double MemBonusIncrement = 0.5;
		//==================================


		public static double MaxBetCount = 200;
		public static double MaxBetMoney = 20000;
		public static double OneBetPoint = 2;
		public static double MinOneBetMoney = 0.1;
		public static double MaxOneBetMoney = 200;
		//==================================
		public static double MaxOutMoneyOneDay = 50000;
		public static double MaxOutMoneyOneTime = 50000;
		public static double MinOutMoneyOneTime = 100;
		public static int MaxOutMoneyTimesOneDay = 3;
		//==================================
		public static string USERINFO_SESSION = "UserInfo_Session";
		public static string USERNAME_SESSION = "UserName_Session";
		//==================================
		public static string LOTTERYPLAYTYPE_SESSION = "LotteryType_Session";
		public static string PLAYTYPE_SESSION = "PlayType_Session";

		public static string SSCPLAYTYPE_SESSION = "SSCPlayType_Session";
		public static string _3DPLAYTYPE_SESSION = "_3DPlayType_Session";
		public static string SSQPLAYTYPE_SESSION = "SSQPlayType_Session";
		public static string SSCRXPLAYTYPE_SESSION = "SSCRXPlayType_Session";

		public static string NSSCPLAYTYPE_SESSION = "NSSCPlayType_Session";
		public static string N_3DPLAYTYPE_SESSION = "N_3DPlayType_Session";
		public static string NSSQPLAYTYPE_SESSION = "NSSQPlayType_Session";
		//==================================
		public static string PLAYTYPERADIO_SESSION = "PlayTypeRadio_Session";
		public static string SSCPLAYTYPERADIO_SESSION = "SSCPlayTypeRadio_Session";
		public static string _3DPLAYTYPERADIO_SESSION = "_3DPlayTypeRadio_Session";
		public static string SSQPLAYTYPERADIO_SESSION = "SSQPlayTypeRadio_Session";

		public static string NSSCPLAYTYPERADIO_SESSION = "NSSCPlayTypeRadio_Session";
		public static string N_3DPLAYTYPERADIO_SESSION = "N_3DPlayTypeRadio_Session";
		public static string NSSQPLAYTYPERADIO_SESSION = "NSSQPlayTypeRadio_Session";
		//==================================
		public static string PLAYTYPENUM_SESSION = "PlayTypeNUM_Session";
		public static string SSCPLAYTYPENUM_SESSION = "SSCPlayTypeNUM_Session";
		public static string _3DPLAYTYPENUM_SESSION = "_3DPlayTypeNUM_Session";
		public static string SSQPLAYTYPENUM_SESSION = "SSQPlayTypeNUM_Session";

		public static string NSSCPLAYTYPENUM_SESSION = "NSSCPlayTypeNUM_Session";
		public static string N_3DPLAYTYPENUM_SESSION = "N_3DPlayTypeNUM_Session";
		public static string NSSQPLAYTYPENUM_SESSION = "NSSQPlayTypeNUM_Session";
		//===================================

		//期号(当前期、上一期)
		public static string CURRENTISSUENO_SESSION = "CurrentIssueNo_Session";
		public static string LASTISSUENO_SESSION = "LastIssueNo_Session";

		//逆向赔率
		public static string REVERSEODDS_SESSION = "ReverseOdds_Session";

		//盈亏记录
		public static ProfitTypeInfo[] ProfitTypeInfos = new ProfitTypeInfo[] {
            new ProfitTypeInfo(0, "全部"), 
            new ProfitTypeInfo(1, "盈亏"), 
            new ProfitTypeInfo(2, "返点"),
            new ProfitTypeInfo(3, "充值"),
            new ProfitTypeInfo(4, "提现"),
            new ProfitTypeInfo(5, "提现返点") };
		//================================
		public static string KFSystem = "http://www41.53kf.com/webCompany.php?arg=slc01&style=1&charset=utf-8";

		public static string SocketIp = "localhost";
		public static int SocketPort = 3397;
		public static string WcfSrvIp = "http://localhost:3397/LotteryService.svc";

	}

	public class EndpointBehavior : IEndpointBehavior
	{
		public void AddBindingParameters(ServiceEndpoint endpoint, System.ServiceModel.Channels.BindingParameterCollection bindingParameters)
		{
		}

		public void ApplyClientBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.ClientRuntime clientRuntime)
		{
			MessageInspector inspector = new MessageInspector();
			clientRuntime.MessageInspectors.Add(inspector);
		}

		public void ApplyDispatchBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.EndpointDispatcher endpointDispatcher)
		{
		}

		public void Validate(ServiceEndpoint endpoint)
		{
		}
	}

	public class MessageInspector : IClientMessageInspector
	{
		public static string MyCustomHeaderContent
		{
			get;
			set;
		}

		public void AfterReceiveReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
		{

		}

		public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel)
		{
			request.Headers.Add(MessageHeader.CreateHeader("username", "", "7692AA70EEF92B42"));
			request.Headers.Add(MessageHeader.CreateHeader("password", "", "00E19868F0C755F0"));
			return null;
		}
	}
}
